package com.club.common.exception;

import com.club.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 捕获业务异常
     */
    @ExceptionHandler(BusinessException.class)
    public R<String> handleBusinessException(BusinessException ex) {
        log.error("业务异常：{}", ex.getMessage());
        return R.error(ex.getMessage());
    }

    /**
     * 捕获全局异常
     */
    @ExceptionHandler(Exception.class)
    public R<String> handleException(Exception ex) {
        log.error("系统异常：{}", ex.getMessage(), ex);
        return R.error("系统内部错误，请联系管理员");
    }
}